package org.example.cloudcommon.mapDB;

import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.HTreeMap;
import org.mapdb.Serializer;

import java.io.File;

public class MapDBExample {
    public static void main(String[] args) {
        File file = new File("mydb");
        DB db = DBMaker.fileDB(file).make();
        HTreeMap<String, String> myMap = db.hashMap("myMap")
                .keySerializer(Serializer.STRING)
                .valueSerializer(Serializer.STRING)
                .createOrOpen();
        myMap.put("key1","value1");
        myMap.put("key2","value2");
        db.commit();
        db.close();
        // 读取

        DB make = DBMaker.fileDB(file).make();
        HTreeMap<String, String> myMap2 = make.hashMap("myMap")
                .keySerializer(Serializer.STRING)
                .valueSerializer(Serializer.STRING)
                .createOrOpen();
        String string = myMap2.get("key1");
        System.out.println("key1"+string);
    }
}
